﻿using System;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using CeA.Reports.Atendimento.DataAccess;
using CeA.Reports.Atendimento.DataAccess.DAO;
using CeA.Reports.Atendimento.DataAccess.DTO;
using Qtech.Reports.Atendimento.Services;
using CeA.Reports.Atendimento.Web.inc.Helpers;
using System.Security.Authentication;


namespace CeA.Reports.Atendimento.Web.site {
    public partial class login : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            //bool x = User.IsInRole("ADMIN");
            FormsAuthentication.SignOut();
        }

        protected void btnLogin_Click(object sender, EventArgs e) {
            LoginDTO user = new LoginDTO();
            user.Login = j_username.Text;
            user.Senha = j_password.Text;

            UsuarioDTO dto = null;

            try {
                dto = CadastroFacade.GetUsuarioAuth(user);
                AuthSessionHelper.CreateNew(dto);
            }
            catch (AuthenticationException ex) {
                cvlMensagem.IsValid = false;
                cvlMensagem.Text = ex.Message;
            }

            if (Page.IsValid) {
                FormsAuthentication.RedirectFromLoginPage(dto.Login, false);
            }
        }
    }
}
